﻿using System;

namespace ProblemsSet
{
    public class Problem_38 : BaseProblem
    {
        public override object GetResult()
        {
            long res = 0;
            for (var i = 1; i < 10000; i++ )
            {
                long vl = i;
                for (var n = 2; n < 10; n++)
                {
                    vl *= (long)(Math.Pow(10, (int)Math.Log10(i * n) + 1));
                    vl += i*n;
                    if (MathLogic.GetCountOfDigits(vl) >= 9) break;
                }
                if (MathLogic.GetCountOfDigits(vl) > 9 || MathLogic.GetDigitSet(vl).Contains(0)) continue;
                if (MathLogic.GetDigitSet(vl).Count != 9) continue;
                if (res < vl) res = vl;
            }
            return res;
        }

        public override string Problem
        {
            get
            {
                return @"Take the number 192 and multiply it by each of 1, 2, and 3:

192  1 = 192
192  2 = 384
192  3 = 576
By concatenating each product we get the 1 to 9 pandigital, 192384576. We will call 192384576 the concatenated product of 192 and (1,2,3)

The same can be achieved by starting with 9 and multiplying by 1, 2, 3, 4, and 5, giving the pandigital, 918273645, which is the concatenated product of 9 and (1,2,3,4,5).

What is the largest 1 to 9 pandigital 9-digit number that can be formed as the concatenated product of an integer with (1,2, ... , n) where n  1?";
            }
        }

        public override bool IsSolved
        {
            get
            {
                return true;
            }
        }

        public override object Answer
        {
            get
            {
                return 932718654;
            }
        }

    }
}
